#ifndef TRIBEMGRDLG_H
#define TRIBEMGRDLG_H
#include "../Core/msgbus_interface.h"
#include "../Core/msgbus_handlerbase.hpp"
#include "../Biz/MsgBusParam/IMTribeParam.h"
#include "../Biz/MsgBusParam/wwbiz.PBTribeMemberInfo.pb.h"
#include <QDialog>
#include <map>
#include <string>
#include <QUrl>

using std::string;
using std::map;

using namespace NetMsgBus;
namespace Ui {
    class TribeMgrDlg;
}
class QListWidgetItem;
class TribeMgrDlg : public QDialog, public MsgHandler<TribeMgrDlg>
{
    Q_OBJECT

public:
    explicit TribeMgrDlg(QWidget *parent = 0);
    ~TribeMgrDlg();
    void SetWWMainUniqueId(const std::string& uniqueid);
    void CleanDataOnLogout();
    void InitMsgHandler();
signals:
    // tribe
    void receiveAllTribeInfoReady(MsgBusParam param);
    void receiveTribeMemberInfoReady(MsgBusParam param);
    void receiveTribeMsgs(MsgBusParam param);
    void tribeMemberClicked(QString memberid);
    void newactivity();
    void openTribeHistory();

public slots:
    // tribe
    void OnSendTribeMsgClicked();
    void OnAnchorClicked(QUrl url);
    void OnTribeListItemClicked(QListWidgetItem* pitem);
    void OnTribeMemberListItemClicked(QListWidgetItem* pitem);
    void OnTribeImageNotify(MsgBusParam param);


private slots:
    // tribe
    void OnReceiveTribeMsgs(MsgBusParam param);
    void OnReceiveAllTribeInfoReady(MsgBusParam param);
    void OnReceiveTribeMemberInfoReady(MsgBusParam param);
    void on_btnHistory_clicked();

    void on_btnSendPic_clicked();

private:
    // tribe
    QString GetTribeMemberDispNameFromId(const wwbiz::PBTribeMemberInfo& meminfo);
    QString GetTribeMemberDispNameFromId(const std::string& tribeid, const std::string& memberid);
    QString GetTribeMemberDispNameFromId(const wwbiz::PBTribeMemberInfoVec& memvec, const std::string &memberid);
    void FillTribeMemberInfo(wwbiz::PBTribeMemberInfoVec& memvec);
    bool OnIMTribeTextMsg(const std::string& msgid, MsgBusParam& param, bool& is_continue);
    bool OnIMAllTribeInfoReady(const std::string& msgid, MsgBusParam& param, bool& is_continue);
    bool OnIMTribeMemberInfoReady(const std::string& msgid, MsgBusParam& param, bool& is_continue);
    Ui::TribeMgrDlg *ui;
    std::string m_wwmain_unique;
    wwbiz::TribeInfoContainerT  m_alltribes;
    //std::map<std::string, wwbiz::TribeMemberInfoVector> m_alltribe_members;
    std::map<std::string, wwbiz::PBTribeMemberInfoVec> m_alltribe_members;

};

#endif // TRIBEMGRDLG_H
